package com.sn.author.service.impl;

import com.sn.author.dao.UserMapper;
import com.sn.author.domain.UserExample;
import com.sn.author.domain.entity.User;
import com.sn.author.filter.content.UserDetail;
import com.sn.author.service.dao.UserService;
import com.sn.author.utils.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @Author xiaom
 * @Date 2020/9/15 21:43
 * @Version 1.0.0
 * @Description <>
 **/
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Optional<UserDetail> getUserDetail(String userName) {
        User user = userMapper.selectByUserName(userName);
        if(user == null){
            return Optional.empty();
        }
        return Optional.of(new UserDetail(BeanUtils.transformFrom(user,UserExample.class)));
    }
}
